package com.shz.controller;


import com.shz.pojo.TbCourse;
import com.shz.service.TbCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程管理 前端控制器
 * </p>
 *
 * @author shz
 * @since 2024-07-29
 */
@RestController
@RequestMapping("/tb-course")
@Api(tags = "课程模块")
public class TbCourseController {
    @Resource
    TbCourseService tbCourseService;
    @ApiOperation(value = "主页随机课程")
    @GetMapping("/getRandomCourse")
    public List<TbCourse> getRandomCourse(){
        List<TbCourse> list = tbCourseService.query().list();
        if(list.size()>6){
            return list.subList(0, 6);
        }
        return list;
    }

    @ApiOperation(value = "课程详情")
    @GetMapping("/getCourse/{id}")
    public TbCourse getCourse(@PathVariable int id){
        TbCourse one = tbCourseService.query().eq("id",id).one();
        return one;
    }

    @ApiOperation(value = "获取该基地所有课程")
    @GetMapping("/getCourseByPlace/{id}")
    public List<TbCourse> getCourseByPlace(@PathVariable int id){
        return tbCourseService.query().eq("base_id",id).list();
    }

}

